package com.lv.suyiyong.hfr.fragment

import androidx.recyclerview.widget.GridLayoutManager
import com.blankj.utilcode.util.SizeUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.lv.common.base.DataBindBaseViewHolder
import com.lv.common.imp.OnPositionTListener
import com.lv.common.widget.recyclerview.decoration.SpacesItemDecoration
import com.lv.service.bean.GoodsBean
import com.lv.service.bean.GoodsItemBean
import com.lv.suyiyong.hfr.R
import com.lv.suyiyong.hfr.adapter.GoodsHAdapter
import com.lv.suyiyong.hfr.databinding.ItemCompanyCategoryRightHeaderRecBinding

/**
 * 作者： ygx
 * 创建日期：2022/6/24 8:10 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 *      _              _           _     _   ____  _             _ _
 *     / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 *    / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 *   / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 *  /_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 *
 */
class CompanyCategoryRightParentAdapter(private val datas: MutableList<GoodsBean>?) :
    BaseQuickAdapter<GoodsBean, DataBindBaseViewHolder>
        (R.layout.item_company_category_right_header_rec, datas) {

    override fun convert(holder: DataBindBaseViewHolder, item: GoodsBean) {
        val mBinding: ItemCompanyCategoryRightHeaderRecBinding =
            holder.getBind() as ItemCompanyCategoryRightHeaderRecBinding
//        mBinding.itemRoot = item.fcname
//        //防止列表闪烁
        mBinding.executePendingBindings()
        val layoutPosition = holder.layoutPosition
        mBinding.tvContent.text = item.attached
        //禁止滑动 布局管理器
        val gridLayoutManager: GridLayoutManager =
            object : GridLayoutManager(context, 3) {
                //禁止竖向滑动 RecyclerView 为垂直状态（VERTICAL）
                override fun canScrollVertically(): Boolean {
                    return false
                }
            }
        mBinding.rvContent.layoutManager = gridLayoutManager

        val items = item.items
        val list = mutableListOf<GoodsItemBean>()
        items?.let { list.addAll(it) }
        val childAdapter = GoodsHAdapter(list)
        mBinding.rvContent.adapter = childAdapter
        mBinding.tvContent.setOnClickListener {
            onViewGroupClickListener?.onClick(
                -1, item
            )
        }
        childAdapter.onViewItemClickListener = OnPositionTListener { position, data ->
            onViewItemClickListener?.onClick(position, data)

        }
    }

    /**
     * 判断position对应的Item是否是组的第一项
     *
     * @param position
     * @return
     * 0 第一个 1 不同项 2 相同项
     */
//    fun isItemHeader(position: Int): Int {
//        return if (position == 0) {
//            0
//        } else {
//            val lastGroupName: Int = datas?.get(position - 1)?.fcaid ?: -100
//            val currentGroupName: Int = datas?.get(position)?.fcaid ?: -100
//            //判断上一个数据的组别和下一个数据的组别是否一致，如果不一致则是不同组，也就是为第一项（头部）
//            return if (lastGroupName != currentGroupName) 1 else 2
//        }
//    }

    var onViewGroupClickListener: OnPositionTListener<GoodsBean>? = null
    var onViewItemClickListener: OnPositionTListener<GoodsItemBean>? = null


}